package com.SouthernWall_404.AgeRight.Common.API.Capability.Provider;

import com.SouthernWall_404.AgeRight.Common.API.Capability.Missions;
import net.minecraft.core.Direction;
import net.minecraft.nbt.CompoundTag;
import net.minecraftforge.common.capabilities.Capability;
import net.minecraftforge.common.capabilities.CapabilityManager;
import net.minecraftforge.common.capabilities.CapabilityToken;
import net.minecraftforge.common.capabilities.ICapabilitySerializable;
import net.minecraftforge.common.util.LazyOptional;
import org.jetbrains.annotations.NotNull;
import org.jetbrains.annotations.Nullable;

public class MissionsProvider implements ICapabilitySerializable<CompoundTag> {
    private Missions missions;

    // 修正：使用Missions而不是Locks
    public static final Capability<Missions> MISSIONS_CAPABILITY = CapabilityManager.get(new CapabilityToken<>(){});

    private final LazyOptional<Missions> lazyOptional = LazyOptional.of(() -> this.missions);

    public MissionsProvider() {
        this.missions = new Missions();
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap, @Nullable Direction side) {
        return getCapability(cap);
    }

    @Override
    public @NotNull <T> LazyOptional<T> getCapability(@NotNull Capability<T> cap) {
        // 修正：检查MISSIONS_CAPABILITY而不是LOCKS
        if(cap == MISSIONS_CAPABILITY) {
            return lazyOptional.cast();
        } else {
            return LazyOptional.empty();
        }
    }

    @Override
    public CompoundTag serializeNBT() {
        return missions.serializeNBT();
    }

    @Override
    public void deserializeNBT(CompoundTag nbt) {
        missions.deserializeNBT(nbt);
    }
}